package cc.rboot.token.configuration;

import cc.rboot.token.core.ITokenAware;
import cc.rboot.token.interceptor.TokenInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
@ConditionalOnBean(ITokenAware.class)
@Import({TokenInterceptor.class})
public class RBootTokenConfiguration implements WebMvcConfigurer {

    @Resource
    public TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**");
    }
}
